package sany.iec.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author 托马斯
 * @Date 2025/7/5 22:24
 * @Description ModbusDataTypeEnum
 */
@AllArgsConstructor
@Getter
public enum ModbusDataTypeEnum {

    BOOL("BOOL", "布尔类型"),

    INT_AB("INTAB", "ShortAB"),

    INT_BA("INTBA", "ShortBA"),

    LONG_ABCD("LONGABCD", "LongABCD"),

    LONG_CDAB("LONGCDAB", "LongCDAB"),

    FLOAT_ABCD("FLOATABCD", "FLOATABCD"),

    FLOAT_CDAB("FLOATCDAB", "FLOATCDAB"),

    ;

    private final String type;

    private final String description;

    public static ModbusDataTypeEnum getModbusDataTypeEnum(String type) {
        if (StringUtils.isBlank(type)) {
            return null;
        }
        for (ModbusDataTypeEnum modbusDataTypeEnum : ModbusDataTypeEnum.values()) {
            if (type.toLowerCase().contains(modbusDataTypeEnum.getType().toLowerCase())) {
                return modbusDataTypeEnum;
            }
        }
        return null;
    }

}
